package Test;

import java.util.Scanner;

class EncryptAndDecyrpt{
    String encrypt(String sourceString,String password){
        char [] p=password.toCharArray();
        int n=p.length;
        char [] c=sourceString.toCharArray();
        int m=c.length;
        for(int k=0;k<m;k++){
            int mima=c[k]+p[k%n];
            c[k]=(char)mima;
        }
        return new String(c);
    }
    String decrypt(String sourceString,String password){
        char [] p=password.toCharArray();
        int n=p.length;
        char [] c=sourceString.toCharArray();
        int m=c.length;
        for(int k=0;k<m;k++){
            int mima=c[k]-p[k%n];
            c[k]=(char)mima;
        }
        return new String(c);
    }
}
public class String_8jiami {
    public  static  void main(String [] args){
        String sourceString="今晚十点进攻";
        EncryptAndDecyrpt person=new EncryptAndDecyrpt();
        System.out.println("输入密码加密："+sourceString);
        Scanner scanner=new Scanner(System.in);
        String password=scanner.nextLine();
        String scecret =person.encrypt(sourceString,password);
        System.out.println("密文"+scecret);
        System.out.println("输入解密密码");
        password=scanner.nextLine();
        String source=person.decrypt(scecret,password);
        System.out.println("明文:"+source);
    }
}
